public class CompoundInterest2 {

  public static void main(String[] args) {

    final int NRATES = 6;
    final int NYEARS = 10;
    final int STARTRATE = 10;

    double[] interestRate = new double[NRATES];
    double[][] balances = new double[NYEARS][NRATES];

    // Initialize the `interestRate` array.
    for (int i = 0; i < interestRate.length; i++)
      interestRate[i] = (STARTRATE + i) / 100.0;

    // Initialize the `balances[0]` array.
    for (int i = 0; i < balances[0].length; i++)
      balances[0][i] = 10000;

    // Calculate balances.
    for (int i = 1; i < balances.length; i++) {
      for (int j = 0; j < balances[0].length; j++) {
        balances[i][j] += balances[i - 1][j] * (1 + interestRate[j]);
      }
    }

    // Print Result.
    for (int i = 0; i < interestRate.length; i++)
      System.out.printf("%9.0f%%", interestRate[i] * 100);
    System.out.println();

    for (int i = 0; i < balances.length; i++) {
      for (int j = 0; j < balances[i].length; j++)
        System.out.printf("%10.2f", balances[i][j]);
      System.out.println();
    }
  }

}
